package api

import (
	"fmt"
	"github.com/EDDYCJY/go-gin-example/pkg/app"
	"github.com/EDDYCJY/go-gin-example/pkg/e"
	"github.com/EDDYCJY/go-gin-example/pkg/util"
	"github.com/gin-gonic/gin"
)

// 查询镜像列表
type ImageListReq struct {
	NodeID string `form:"node_id" binding:"required"`
}

func Handle_ImageList(c *gin.Context) {
	appG := app.Gin{C: c}

	var req ImageListReq
	if err := c.ShouldBindQuery(&req); err != nil {
		appG.ResponseError(e.ERROR, "请求参数错误:"+err.Error())
		return
	}

	api := fmt.Sprintf("/api/v1/image/base/list?node_id=%v", req.NodeID)

	data := util.GetRequest(api)
	if data.Errcode != 0 {
		appG.ResponseError(data.Errcode, data.Errmsg)
	} else {
		appG.ResponseSuccess(data.Data)
	}
}
